<?php
	require_once "admin_header.php";
	$phim=new Phim;
	$databa=new Database;
	$display=15;
	if(isset($_GET['page']) && (int)$_GET['page'])
	{
		$page=$_GET['page'];}
	else
	{
		$sql="select count(*) as num from phim group by tenphim";
		$query=$databa->query($sql);;
		$data="";
		while($row=$databa->fetch())
		{
			$data[]=$row;
		}
		if(is_array($data))
		{
			$record=0;
			foreach($data as $item)
			{
				$record++;
			}
		}
		else
			$record=0;
		if($record > $display)
		{ 
			$page=ceil($record/$display);
		}
		else
		{
			$page=1;
		}
	}
	$start=((isset($_GET['start']) && (int)$_GET['start']>0 ))? $_GET['start'] : 0;
	$sql2="select * from phim group by tenphim order by maphim DESC limit $start,$display ";
	$result=$phim->danhsach_phim_pt($sql2);
?>
<script type="text/javascript" language="javascript">
	page=1;
</script>
<div class="heading">
    <a>trang chủ</a>
</div>
<div class="content_page">
	<div class="ds">
        <table border="1">
            <tr>
                <th>STT</th>
                <th>Mã Phim</th>
                <th>Tên Phim</th>
                <th>Năm Sản Xuất</th>
                <th> Ngày Đăng</th>
                <th>Đăng thêm tập</th>
            </tr>
            <?php
                
                $stt=0;
                if(is_array($result))
				{
					foreach($result as $k)
					{
						$stt++;
						echo "<td class='list_pq'>$stt</td><td class='list_pq'>$k[maphim]</td><td class='list_tp'><a href='admin_danhsach_tapphim.php?tenphim=$k[tenphim]'>$k[tenphim]</a></td><td class='list_pq'>$k[namsx]</td><td>$k[ngaydang]</td><td class='list_dtm'><a href='admin_dangtapphim.php?id=$k[maphim]'>Đăng Tập Mới</a></td>";
						echo "</tr>";
					}
				}
				else
					echo "<tr><td colspan='6'><i>Không có phim nào</i></td></tr>";
                
            ?>
        </table>
        <ul >
		   <?php
           $b=$page;
              if($b>1)
              {
                  $next=$start+$display;
                  $prev=$start-$display;
                  $current=($start/$display)+1;
                  if($current!=1)
                  {
                      echo "<li><a href='admin_index.php?start=$prev'> &nbsp; << &nbsp; </a></li>";
                  }
                  $begin=$current-1;
                  if($begin<1)
                      $begin=1;
                  $end=$current+1;
                  if($end>$page)
                      $end=$page;
                  for($i=$begin;$i<=$end;$i++)
                  {
                      if(($i==$begin && $begin>1) )
                          echo "<li style='border:none; background:transparent; font-weight:bold'><span>....</span></li>";
                      if( $current!=$i)
                      {
                          echo "<li class='num'><a href='admin_index.php?start=" , ($display*($i-1)) ,"'>$i</a></li>";
                      }
                      else
                      {
                          echo "<li class='num'><a style='background-color:#000;color:#FFF;font-weight: bold;'>$i</a></li>";
                      }
                      if(($i==$end && $end<$page) )
                          echo "<li style='border:none; background:transparent; font-weight:bold'><span>....</span></li>";
                  }
                  if($current!=$b)
                  {
                      echo "<li><a href='admin_index.php?start=$next'> &nbsp; >> &nbsp;</a></li>";
                  }
              }
           ?>
       </ul>
	</div>
</div>
<?php
	require_once "admin_footer.php";
?>

                	
                
